import 'package:chat/generated/l10n.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:get/get.dart';

class MessageListScreen extends StatelessWidget {
  const MessageListScreen({super.key});

  void _showCustomDialog(BuildContext context) {
    showGeneralDialog(
      context: context,
      barrierDismissible: true,
      barrierLabel: '',
      transitionDuration: const Duration(milliseconds: 300),
      pageBuilder: (context, animation1, animation2) => Container(),
      transitionBuilder: (context, animation, secondaryAnimation, child) {
        return Center(
          child: Transform(
            transform: Matrix4.identity()..scale(animation.value, animation.value),
            alignment: Alignment.center,
            child: Opacity(
              opacity: animation.value,
              child: AlertDialog(
                backgroundColor: Colors.transparent,
                contentPadding: EdgeInsets.zero,
                insetPadding: const EdgeInsets.all(20),
                content: Container(
                  width: MediaQuery.of(context).size.width * 0.8,
                  height: MediaQuery.of(context).size.height * 0.6,
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(20),
                    image: const DecorationImage(
                      image: AssetImage('assets/images/widget_zyq_icon.webp'),
                      fit: BoxFit.cover,
                    ),
                  ),
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      const Text(
                        '弹框内容',
                        style: TextStyle(
                          color: Colors.white,
                          fontSize: 24,
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                      const SizedBox(height: 20),
                      ElevatedButton(
                        onPressed: () => Navigator.of(context).pop(),
                        child: const Text('关闭'),
                      ),
                    ],
                  ),
                ),
              ),
            ),
          ),
        );
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.transparent,
      floatingActionButton: FloatingActionButton(
        onPressed: () => _showCustomDialog(context),
        backgroundColor: Colors.blue,
        child: const Icon(Icons.add, color: Colors.white),
      ),
      body: Stack(
        children: [
          // 全屏背景图层
          Positioned.fill(
            child: Image.asset(
              'assets/images/dl_bj_img.webp',
              fit: BoxFit.cover,
            ),
          ),

          // 原AppBar内容（现在作为普通组件）
          Positioned(
            top: MediaQuery.of(context).padding.top, // 适配状态栏高度
            left: 0,
            right: 0,
            child: Container(
              height: kToolbarHeight, // 保持与AppBar相同高度
              color: Colors.transparent,
              child: Row(
                children: [
                  const Padding(
                    padding: EdgeInsets.only(left: 16.0),
                    child: Text(
                      '聊天',
                      style: TextStyle(
                        fontSize: 20,
                        fontWeight: FontWeight.bold,
                        color: Colors.black,
                      ),
                    ),
                  ),
                  const Spacer(),
                  IconButton(
                    icon: Image.asset(
                      'assets/images/friend_album.jpg',
                      width: 34,
                      height: 34,
                    ),
                    onPressed: () => Get.toNamed('/friendListScreen'),
                  ),
                  IconButton(
                    icon: Image.asset(
                      'assets/images/add_group.jpg',
                      width: 34,
                      height: 34,
                    ),
                    onPressed: () => Get.toNamed('/friendListScreen'),
                  ),
                ],
              ),
            ),
          ),

          // 原有内容（下移避免重叠）
          Padding(
            padding: EdgeInsets.only(top: kToolbarHeight + MediaQuery.of(context).padding.top),
            child: Column(
              children: [
                Center(
                  child: GestureDetector(
                    onTap: () {
                      final currentLocale = Get.locale ?? const Locale('zh');
                      Get.updateLocale(currentLocale.languageCode == 'zh' ? const Locale('en') : const Locale('zh'));
                    },
                    child: Stack(
                      alignment: AlignmentDirectional.center,
                      children: [
                        SizedBox(child: SvgPicture.asset('assets/images/Rectangle4112.svg')),
                        Text(S.of(context).hello),
                      ],
                    ),
                  ),
                ),
                const SizedBox(height: 10),
                Center(
                  child: Stack(
                    alignment: AlignmentDirectional.center,
                    children: [
                      SizedBox(
                        width: 100,
                        height: 60,
                        child: SvgPicture.asset(
                          'assets/images/Rectangle4112.svg',
                          fit: BoxFit.fill,
                        ),
                      ),
                      const Text('登陆'),
                    ],
                  ),
                ),
                Image.asset('assets/images/setting_map_icon.webp'),
                Image.asset('assets/images/pph5_xz_btn.webp'),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
